<?php

namespace App\model\agent;

use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;

/**
 * App\model\agent\AgentPositon
 *
 * @property int $id
 * @property string|null $name
 * @property int|null $sort
 * @property \Illuminate\Support\Carbon|null $created_at
 * @property \Illuminate\Support\Carbon|null $updated_at
 * @method static \Illuminate\Database\Eloquent\Builder|\App\model\agent\AgentPositon newModelQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|\App\model\agent\AgentPositon newQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|\App\model\agent\AgentPositon query()
 * @method static \Illuminate\Database\Eloquent\Builder|\App\model\agent\AgentPositon whereCreatedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\model\agent\AgentPositon whereId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\model\agent\AgentPositon whereName($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\model\agent\AgentPositon whereSort($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\model\agent\AgentPositon whereUpdatedAt($value)
 * @mixin \Eloquent
 */
class AgentPositon extends Model
{
    protected  $table='agent_positon';
    /**
     * 把约束加到 Eloquent 查询构造中。
     *
     * @param  \Illuminate\Database\Eloquent\Builder  $builder
     * @param  \Illuminate\Database\Eloquent\Model  $model
     * @return void
     */
    public function apply(Builder $builder, Model $model)
    {
        $builder->orderBy('sort','desc')->orderBy('id','desc');
    }
    public static function getSelectOptions()
    {
        $options = \DB::table('agent_positon')->select('id','name as text')->get();

        foreach ($options as $option){
            $selectOption[$option->id] = $option->text;
        }
        return $selectOption;
    }
}
